package hn.cch.mybatis.plus.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

@Component
public class FillMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        fill(metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        fill(metaObject);
    }

    public void fill(MetaObject metaObject) {
        String name = "fill";
        Object obj = getFieldValByName(name, metaObject);
        if (obj instanceof String) {
            String str = (String) obj;
            String fill = String.format("%s**", str.charAt(0));
            setFieldValByName(name, fill, metaObject);
        }
    }

}
